package access.spg.android.com.accessibilitytest

import android.content.Context
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.provider.Settings
import android.text.TextUtils
import java.io.File

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
//        if(!isAccessibilitySettingsOn(this))
//        {
            startActivity(Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS))
//        }
    }



    private fun isAccessibilitySettingsOn(context: Context): Boolean {
        val service = context.packageName + File.separator + AutoPunchCardService::class.java.canonicalName
        val accessibilityEnabled = Settings.Secure.getInt(context.contentResolver,
                Settings.Secure.ACCESSIBILITY_ENABLED)
        val splitter = TextUtils.SimpleStringSplitter(':')
        if (accessibilityEnabled != 1) return false
        val value = Settings.Secure.getString(context.contentResolver,
                Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES) ?: return false
        splitter.setString(value)
        return splitter.contains(service)
    }


}
